package com.ruoyi.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.net.URI;

@Slf4j
@Component
public class CustomGatewayFilter implements GatewayFilter, Ordered {
 
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        ServerHttpRequest request = exchange.getRequest();
        URI uri = request.getURI();
        String path1 = uri.getPath();
        MultiValueMap<String, String> queryParams = request.getQueryParams();
        HttpMethod method = request.getMethod();

        log.info("=============经过过滤器的一些信息=====================\n" +
                "method:"+method+"\nuri.getPath:"+path1+"\nqueryParams:"+queryParams);
        return chain.filter(exchange);// 继续向下执行
    }
 
    @Override
    public int getOrder() {
        return 0;
    }
}